package com.yxuan.springboot.controller;

import com.yxuan.springboot.model.VolunteerForm;
import com.yxuan.springboot.service.VolunteerFormService;
import com.yxuan.springboot.util.Result;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * @author zchao
 * VolunteerForm控制器
 * @date 2023-06-16 16:54:06
 */
@Slf4j
@Controller
@Api(tags = "")
@RequestMapping(value = "/volunteerform", method = {RequestMethod.POST, RequestMethod.GET})
public class VolunteerFormController extends BaseController<VolunteerForm> {

    @Autowired
    private VolunteerFormService volunteerFormService;


    //    添加志愿表
    @RequestMapping("/saveVolunteerform")
    @ResponseBody
    public HashMap<String, Object> saveVolunteerform(@RequestBody Map map) throws Exception {
        try {
            return volunteerFormService.saveVolunteerform(map);
        } catch (Exception e) {
            HashMap<String, Object> result = new HashMap<>();
            log.error(e.getMessage());
            result.put("result", ERROR);
            return result;
        }
    }


    //    根据用户id查询所有志愿表
    @RequestMapping("/volunteerformList")
    @ResponseBody
    public HashMap<String, Object> volunteerformList(@RequestBody Map map) throws Exception {
        try {
            return volunteerFormService.volunteerformList(map);
        } catch (Exception e) {
            HashMap<String, Object> result = new HashMap<>();
            log.error(e.getMessage());
            result.put("result", ERROR);
            return result;
        }
    }

    //    根据志愿表id查询所有所需信息
    @RequestMapping("/volunteerformDetails")
    @ResponseBody
    public HashMap<String, Object> volunteerformDetails(@RequestBody Map map) throws Exception {
        try {
            return volunteerFormService.volunteerformDetails(map);
        } catch (Exception e) {
            HashMap<String, Object> result = new HashMap<>();
            log.error(e.getMessage());
            result.put("result", ERROR);
            return result;
        }
    }

    //   根据用户id获取表的数量
    @RequestMapping("/countVolunteerform")
    @ResponseBody
    public Result countVolunteerform(@RequestBody Map map) throws Exception {
        try {
            return new Result(volunteerFormService.countVolunteerform(map), SUCCESSCODE) ;
        } catch (Exception e) {
            return new Result(FAILCODE);
        }
    }

    @RequestMapping("/delVolunteerform")
    @ResponseBody
    public Result delVolunteerform(@RequestBody Map map) throws Exception {
        try {
            return new Result(volunteerFormService.delVolunteerform(map), SUCCESSCODE);
        } catch (Exception e) {
            return new Result(FAILCODE);
        }
    }
}
